package com.gzhryc.common;

import java.util.Date;
import java.util.Random;
import java.util.UUID;

import org.apache.commons.lang3.time.DateFormatUtils;

public class IDTools {

	public static String getUUID() {
		return UUID.randomUUID().toString().replace("-", "");
	}

	public synchronized static String getTimestampID() {
		Long timestamp = System.currentTimeMillis();
		return timestamp.toString();
	}

	/**
	 * 获取16进制的时间戳
	 * @return
	 */
	public synchronized static String get16TimestampID() {
		Long timestamp = System.currentTimeMillis();
		return Long.toString(timestamp,16);
	}

	public synchronized static String getTimestampNanoID() {
		Long timestamp = System.nanoTime();
		return timestamp.toString();
	}

	public synchronized static String getTimeID() {
		return DateFormatUtils.format(new Date(), "yyyyMMddHHmmssS");
	}

	public synchronized static String getTimestampSecondID() {
		Long timestamp = System.currentTimeMillis() / 1000;
		return timestamp.toString();
	}

	public synchronized static String getTimestampMinuteID() {
		return DateFormatUtils.format(new Date(), "yyyyMMddHHmm");
	}

	public synchronized static String getRandomNumberStr(int size) {
		String result = "";
		Random random = new Random();
		for (int i = 0; i < size; i++) {
			int number = random.nextInt(9);
			result = result + number;
		}
		return result;
	}
}
